package cc.fs.kotlinproject

import android.app.Activity
import android.app.AlertDialog
import android.content.DialogInterface
import android.os.Bundle
import android.os.Message
import android.support.v4.app.FragmentManager
import android.view.LayoutInflater
import android.view.View
import cc.fs.kotlinproject.utlis.*
import org.jetbrains.anko.*

/**
 * Created by fostion on 2015/8/14.
 */

public class FrashActivity : BaseActivity() {

    var dialog: AlertDialogHelper? = null
    var dialog2:AlertDialogHelper2? = null
    var dialog3:AlertDialogHelper3? = null

    companion object {
        fun start(context: Activity) {
            val intent = getIntent<FrashActivity>(context)
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super<BaseActivity>.onCreate(savedInstanceState)
        dialog = AlertDialogHelper.newInstance(R.string.hello_world)
        setUpView()

        dialog2 = AlertDialogHelper2.newInstance(this).title("abc")
                ?.content("123456")
                 ?.sure("abc",{dialog,which -> e("-----0000")})

        var v = LayoutInflater.from(this).inflate(R.layout.activity_login,null);
        dialog3 = dialogFragment(_this){
//            contentView = v
            title = "123"
            sureClicke("abc",{dialog,which -> e("-----333333sure")})
            cancleClick("abc",{dialog,which -> e("-----33333cancle")})
        }



        //        myDialog("123").show(getFragmentManager(),"12345")
    }

    fun setUpView() {
        verticalLayout {
            val name = editText()
            button("Dialog Fragment") {
                onClick {
                    toast("Hello, ${name.text}!")
                    dialog?.sureCallback = {
                        e("--------- sure")
                    }

                    dialog?.cancleCallback = {
                        e("--------- cancle")
                    }
                    dialog?.show(getFragmentManager(), "dialog")
                }
            }

            button("Normal Fragment") {
                onClick {
                    //                    val dialog1 = AlertDialog.Builder(_this)
                    //                            .setIcon(R.mipmap.ic_launcher)
                    //                            .setTitle("Normal Dialog")
                    //                            .setPositiveButton("sure", object : DialogInterface.OnClickListener {
                    //                                override fun onClick(dialog: DialogInterface, which: Int) {
                    //                                }
                    //                            })
                    //                            .setNegativeButton("cancle", object : DialogInterface.OnClickListener {
                    //                                override fun onClick(dialog: DialogInterface, which: Int) {
                    //                                }
                    //                            }).create()
                    //                    dialog1.show()
                    dialog3?.show(getFragmentManager(),"dialog")

                }
            }
        }
    }

    override fun handler(message: Message) {
    }

}